package com.jinlejia.erp.ui.house.prospect;


import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;

import com.jinlejia.erp.R;
import com.jinlejia.erp.databinding.FragmentProspectUploadWarehouseBinding;
import com.jinlejia.erp.ui.house.prospect.bean.SurveyPictureBean;


/**
 * 上传或修改
 * 厂房/仓库类
 * 的图片
 */
public class ProspectUploadWarehouseFragment extends Fragment implements ProspectUploadImageActivity.HousePictureListener{


    public ProspectUploadWarehouseFragment() {
        // Required empty public constructor
    }

    private FragmentHelper fragmentHelper;
    private Helper helper;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        helper = Helper.init(this.getContext());
    }
    private FragmentProspectUploadWarehouseBinding binding;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_prospect_upload_warehouse, container, false);
        binding = DataBindingUtil.bind(view);
        if (getArguments() != null) {
            Bundle bundle = getArguments();
            String houseSourceCode = bundle.getString(Type.PARAM.HOUSE_SOURCE_CODE);
            String houseSourceType = bundle.getString(Type.PARAM.HOUSE_SOURCE_TYPE);
            fragmentHelper = FragmentHelper.init(this,houseSourceCode,houseSourceType,helper);
            initView();
        }
        SurveyPictureBean bean = fragmentHelper.getSourceInfo();
        initView(bean);
        return view;
    }

    private void initView() {

        //室内照片 must 2
        fragmentHelper.createAdapterAndSetToGridView(binding.indoorGridView,binding.indoorHeaderView,
                2,true,true);

        //卫生间 1
        fragmentHelper.createAdapterAndSetToGridView(binding.toiletGridView,binding.toiletHeaderView,
                1,false,true);

        //厨房 1
        fragmentHelper.createAdapterAndSetToGridView(binding.kitchenGridView,binding.kitchenHeaderView,
                1,false,true);

        //街景 1
        fragmentHelper.createAdapterAndSetToGridView(binding.streetGridView,binding.streetHeaderView,
                1,false,false);

        //门头 1
        fragmentHelper.createAdapterAndSetToGridView(binding.doorGridView,binding.doorHeaderView,
                1,false,false);

        //院子 1
        fragmentHelper.createAdapterAndSetToGridView(binding.courtyardGridView,binding.courtyardHeaderView,
                1,false,false);
    }

    private void initView(SurveyPictureBean bean){
        if (bean==null)return;
        //室内照片 must 2
        fragmentHelper.updateAdapterSource(binding.indoorGridView,binding.indoorHeaderView);

        //卫生间 1
        fragmentHelper.updateAdapterSource(binding.toiletGridView,binding.toiletHeaderView);

        //厨房 1
        fragmentHelper.updateAdapterSource(binding.kitchenGridView,binding.kitchenHeaderView);

        //街景 1
        fragmentHelper.updateAdapterSource(binding.streetGridView,binding.streetHeaderView);

        //门头 1
        fragmentHelper.updateAdapterSource(binding.doorGridView,binding.doorHeaderView);

        //院子 1
        fragmentHelper.updateAdapterSource(binding.courtyardGridView,binding.courtyardHeaderView);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        fragmentHelper.onActivityResult(requestCode, resultCode, data);
    }

    @Override
    public String checkPicturesResult() {
        return fragmentHelper.checkPicturesResult();
    }

    @Override
    public SurveyPictureBean getPicturesResult() {
        return fragmentHelper.getPicturesResult();
    }
}
